<?php

function generaLayoutJS($nomtaula,$numTaules){

$variable = "
var pantalla = new Ext.Panel({
	region: 'center',
	id: 'content-panel',
	layout: 'card',
	activeItem: 0,
	items: [
";
	for($i=0; $i < $numTaules; $i++){
		if($nomtaula[$i] != ""){
			$variable .= "$nomtaula[$i]TabPanel,\n";
		}
	}
	$variable = substr ($variable, 0, -2); //eliminem ,\n de l'ultim camp
		
$variable .= "
	]
});

var logo = new Ext.Panel({
	id: 'logoPanel',
	layout: 'fit',
	region: 'north',
	border: false,
	width: 200,
	height: 100
});

 var arbre = new Ext.tree.TreePanel({
	id: 'tree-panel',
	layout: 'fit',
	region:'center',
	border: false,
	width: 200,
	autoScroll: true,
	//tree-specific configs:
	rootVisible: false,
	lines: false,
	singleExpand: false,
	useArrows: true,
	loader: new Ext.tree.TreeLoader({
		dataUrl:'menu.json'
	}),
	root: new Ext.tree.AsyncTreeNode()
});

var menu = new Ext.Panel({
	layout: 'border',
	region: 'west',
	border: true,
	collapsible: true,
	title: NOM_window_menu,
	width: 200,
	autoScroll: true,
	split: true,
	items: [logo, arbre]
});

arbre.on('click', function(n){
	var sn = this.selModel.selNode || {}; // selNode is null on initial selection
	if(n.leaf && n.id != sn.id){  // ignore clicks on folders and currently selected node 
		if( n.id == 'logout' ){
			logout();
		}else{
			//Ext.getCmp(n.id + '-panel').items.get(0).items.get(0).store.reload();
			Ext.getCmp('content-panel').layout.setActiveItem(n.id + '-panel');
		}
	}
});

function logout(){
	 Ext.Ajax.request({   
		waitMsg: AJAX_wait,
		url: 'php/logout.php',
		success: function(response){  
		  window.location=('index.html');
		},
		failure: function(response){
		  var result=response.responseText;
		  Ext.MessageBox.alert(NOM_window_alert, ERROR_bbdd);	       
		} 
	});
}

Ext.onReady(function(){
	Ext.QuickTips.init();
	
	var viewport = new Ext.Viewport({
	    layout: 'border',
	    items: [menu, pantalla]
	});
});
";

return $variable;
}

?>